package com.pdstudio.carrecom.ui.activity.myclub;

import java.util.ArrayList;
import java.util.List;

import com.pdstudio.carrecom.R;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.pdstudio.carrecom.common.BaseFragmentActivity;
import com.pdstudio.carrecom.ui.fragment.myclub.FragmentPoints1;
import com.pdstudio.carrecom.ui.fragment.myclub.FragmentPoints2;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 我的积分
 * 类: ActivityMyPoints <br>
 * 描述: TODO <br>
 * 作者: xiangzhaoyu  <br>
 * 时间: 2015-7-16 下午5:15:59
 */
public class ActivityMyPoints extends BaseFragmentActivity {
	
	private View customLiveIndexTitleView;
	private TextView txtTitle;
	private ImageView ivBack;
	
	private Fragment mFragment;
	private FragmentPagerAdapter mAdapter;
	private List<Fragment> mFragments;
	private ViewPager mViewPager;
	
	private LinearLayout mP,mG;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_myclub_mypoints_main);
		_context = this;

		initTitle();
		InitialView();


		setSelect(0);

		// Intent intent = new Intent(_context,
		// ActivitySelectBrandsSlide.class);
		// startActivity(intent);
	}	
	private void initTitle() {
		txtTitle = (TextView) findViewById(R.id.title_text_nav);

		txtTitle.setText("我的积分");

		ivBack = (ImageView) findViewById(R.id.title_back);
		ivBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();				
			}
		});
	}
	
	private void InitialView(){
		mViewPager = (ViewPager) findViewById(R.id.id_main_viewpager);

		mP = (LinearLayout) findViewById(R.id.ll_mypoint);
		mP.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setSelect(0);
			}});
		mG = (LinearLayout) findViewById(R.id.ll_getrecord);
		mG.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setSelect(1);
			}});

		mFragments = new ArrayList<Fragment>();
		Fragment mTab01 = new FragmentPoints1();
		Fragment mTab02 = new FragmentPoints2();
		mFragments.add(mTab01);
		mFragments.add(mTab02);
		
		mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

			@Override
			public int getCount() {
				return mFragments.size();
			}

			@Override
			public Fragment getItem(int arg0) {
				return mFragments.get(arg0);
			}
		};
		mViewPager.setAdapter(mAdapter);

		mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				int currentItem = mViewPager.getCurrentItem();
				setTab(currentItem);
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});


	}
	
	private void setSelect(int i) {
		setTab(i);
		mViewPager.setCurrentItem(i);
	}
	
	private void setTab(int i) {
		resetImgs();

		switch (i) {

		case 0:
			mP.setBackgroundColor(Color.GRAY);
			break;
		case 1:
			mG.setBackgroundColor(Color.GRAY);
			break;
		}
	}
	
	private void resetImgs() {
		mP.setBackgroundColor(Color.rgb(153, 153, 153));
		mG.setBackgroundColor(Color.rgb(153, 153, 153));
	}

	
	
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /*在这里，我们通过碎片管理器中的Tag，就是每个碎片的名称，来获取对应的fragment*/
        
        /*然后在碎片中调用重写的onActivityResult方法*/
        mFragment.onActivityResult(requestCode, resultCode, data);
    }


}
